<?php
namespace Bojin\Controller;
use Think\Controller;
class LoginController extends Controller {
	
	public function login()
	{
		$res = M("Customer")->where("is_del = 0 and id=".$customer_id)->getField("id");
		dump(M("Customer")->_sql());
		$type = I("param.type");
    	if(is_numeric($type) && $type){
    		$this->redirect(C("URL_TYPE")[$type]);
    	}else{
			$this->display();
    	}
    }
	//发起快捷支付订单
     public function createQuickOrder()
    {
        $key = 'gNociwieX1aCSkhvVemcXkaF9KVmkXm8';
        $data['merid'] = 'yft2017082500005';
        $data['merchantOutOrderNo'] = time().rand(100000,999999);
        $data['notifyUrl'] = 'https://alipay.3c-buy.com/api/callback';
        $data['noncestr'] = '12345678910';
        $data['orderMoney'] = 1;
        $data['orderTime'] = date('YmdHis');
        $signstr = 'merchantOutOrderNo='.$data['merchantOutOrderNo'].'&merid='.$data['merid'].'&noncestr='.$data['noncestr'].'&notifyUrl='.$data['notifyUrl'].'&orderMoney='.$data['orderMoney'].'&orderTime='.$data['orderTime'];
        $signstr.= '&key='.$key;
        $data['sign'] = md5($signstr);
        $url = 'https://alipay.3c-buy.com/api/createQuickOrder ';
        $str =  "<form id='pay_form' method='POST' action=".$url.">";

        foreach($data as $key=>$value){
          $str.="<input type='hidden' id='".$key."' name='".$key."' value='".$value."' />";
        }
        $str.="</form><script>function submit() {
            document.getElementById('pay_form').submit();
          }window.onload = submit;</script>";
        echo $str;
    }
    
    public function ceshi(){
    	$this->createQuickOrder();
    }

	public function loginlist()
	{

		$user=I("user_name");
		$pwd=I("user_pwd");
		//print_r($user);
		//print_r($pwd);die;
		$res=M("ChannelAdmin");
		//echo 1;die;
		// print_r($user);
		// print_r($pwd);die;
		$list=$res->where("admin_name='$user'")->find();
		if($list['status']=='0')
		{
			$this->error("该账号暂时无法使用");

		}
		// print_r($list);die;
		if($list)
		{
			if($list['admin_powd']==md5($pwd))
			{
				session("user",$list);
				
				$this->success("登录成功",U("rbac/channeluser"),2);
				
			}else{
				$this->error("密码有误");
			}
		}else{
			$this->error("该用户不存在");
		}
	}
	public function cancellation()
	{
		session('user','');
		$this->display('login');
	}


}